package com.booksystem.campuslibrarymanagementsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.booksystem.campuslibrarymanagementsystem.commen.result.adminresult.SendEmailManagementR.GetEmailR;
import com.booksystem.campuslibrarymanagementsystem.entity.AccountTable;
import com.booksystem.campuslibrarymanagementsystem.entity.UserTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AccountTableMapper extends BaseMapper<AccountTable> {
    //通过学号查询单条信息
    @Select("select * from account_table where account = #{account}")
    AccountTable queryByAccount(String account);

    //通过邮箱查询单条信息
    @Select("select * from account_table where email = #{email}")
    List<AccountTable> queryByEmail(String email);

    //获取所有邮箱
    @Select("select email from account_table")
    List<GetEmailR> GetEmails();

    //通过状态查询列表
    @Select("select * from account_table where state = #{state}")
    List<AccountTable> queryByState(String state);

    //通过学号修改密码和salt
    @Update("update account_table set password = #{password},salt = #{salt} where account= #{account}")
    boolean upDataPswAndSalt(String account,String password,String salt);

    //通过学号修改密码和salt和state，用于管理员审批
    @Update("update account_table set password = #{password},salt = #{salt},state = #{state} where account= #{account}")
    boolean upDataPswAndSaltAndState(String account,String password,String salt,String state);

    //通过学号修改身份user，approval，admin
    @Update("update account_table set identity = #{identity} where account= #{account}")
    boolean upDataIdentity(String account,String identity);

    //通过学号修改状态
    @Update("update account_table set state = #{state} where account= #{account}")
    boolean upDataState(String account,String state);

    //动态查询（学号，名字，身份，状态）
    List<AccountTable> selectListAccount(String account,String name,String identity, String state);

    //通过学号修改name
    @Update("update account_table set name = #{name} where account= #{account}")
    boolean upDataName(String account,String name);

    //更新名称和邮箱
    @Update("update account_table set email = #{email},name = #{name} where account= #{account}")
    boolean upDataEmailAndName(String account,String email,String name);

    @Select("SELECT account FROM account_table WHERE name =#{name}")
    String getAccountId(@Param("name") String name);

    //更新账户信息
    @Update("UPDATE account_table\n" +
            "    SET password = #{password}\n" +
            "    WHERE account = #{account}")
    boolean updateAccount(AccountTable account);

    //更新账户信息
    @Update("UPDATE account_table\n" +
            "    SET email = #{email}\n" +
            "    WHERE account = #{account}")
    boolean updateAccountemail(AccountTable account);
}
